#!/usr/bin/env python
# $Id: test2-29.py df54dec975f4 2012/09/09 20:22:40 pgurumur $
# Copyright (c) 2012 Prabhu Gurumurthy <pgurumur@gmail.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

__version__  = "$Revision: df54dec975f4 $"
__author__   = "$Author: pgurumur $"
__modified__ = "$Date: 2012-09-09 20:22:40Z $"

from venya.lib import stdlib

class test(dict):
   def __init__(self, *args, **kwargs):
      super(test, self).__init__(*args, **kwargs)
      self.update(*args, **kwargs)
      
   def __getattr__(self, key):
      retval = None
      if key in self:
         retval = super(test, self).__getitem__(key)

      return retval

   def __nonzero__(self):
      flag = False
      if hasattr(self, "foo"):
         flag = True

      return flag

   def __len__(self):
      return len(self.keys())

test1 = test(foo = stdlib.GetRandomString(10))
if test1:
   print "fooo"

print(dir(test1))
if hasattr(test1, "foo"):
   print(test1.foo)

test1["bar"] = stdlib.GetRandomString(15)
print test1.bar
if isinstance(test1, dict):
   print("asjdhskfjdsfsd")
